package cn.gcjxsc.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author pumbaa
 * @since 1.0
 */
@Service
public class AuthService {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    private static final String HASH_KEY = "rw_merchant";

    /**
     * 取得php登陆iden值
     * @param key 键值
     * @return
     */
    public Integer getAuthIden(String key) {
        Map<Object, Object> entries = stringRedisTemplate.opsForHash().entries(HASH_KEY);
        Object val = entries.get(key);
        return val == null ? null : Integer.valueOf(String.valueOf(val));
    }

    public Long getExpireTime(String key){
        Map<Object, Object> entries = stringRedisTemplate.opsForHash().entries(HASH_KEY);
        Object val = entries.get(key);
        return val == null ? null : Long.valueOf(String.valueOf(val));
    }

    public void expireKeys(Object... keys){
        stringRedisTemplate.opsForHash().delete(HASH_KEY, keys);
    }

    public void updateExpireTime(String key, long time) {
        stringRedisTemplate.opsForHash().put(HASH_KEY, key, time + "");
    }
}
